package com.jiang.view;

import com.jiang.service.FileClientService;
import com.jiang.service.MessageClientService;
import com.jiang.service.UserClientService;
import com.jiang.utils.Utility;

import java.time.Year;

/**
 * @author Jiang
 * @version 1.0
 * @date 2023/11/28 22:59
 * 登录的菜单界面
 */
public class QQView {
    private boolean loop = true;
    private String key = ""; // 接收用户键盘输入
    private UserClientService userClientService = new UserClientService(); // 登录服务
    private MessageClientService messageClientService = new MessageClientService(); // 聊天服务
    private FileClientService fileClientService = new FileClientService(); // 传输文件服务

    private void mainMenu() {
        while (loop) {
            System.out.println("=====欢迎登录网络登录系统======");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 9 退出系统");

            System.out.print("请输入你的选择: ");
            key = Utility.readString(1);

            switch (key) {
                case "1":
                    System.out.print("请输入用户名: ");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密码: ");
                    String pwd = Utility.readString(50);

                    if (userClientService.checkUser(userId, pwd)) {
                        System.out.println("======欢迎(" + userId + "登录成功)======");
                        while (loop) {
                            System.out.println("\n======网络通信系统二级菜单(用户" + userId + ")======");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私聊消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出系统");

                            System.out.print("请输入你的选择: ");
                            key = Utility.readString(1);

                            switch (key) {
                                case "1":
                                    userClientService.onlineFriedList();
                                    break;
                                case "2":
                                    System.out.print("请输入想对大家说的话：");
                                    String con = Utility.readString(100);
                                    messageClientService.sendMessageToAll(con, userId);
                                    break;
                                case "3":
                                    System.out.print("请输入想聊天的用户号(在线)：");
                                    String getterId = Utility.readString(50);
                                    System.out.print("请输入想说的话：");
                                    String content = Utility.readString(100);
                                    messageClientService.sendMessageToOne(content, userId, getterId);
                                    break;
                                case "4":
                                    System.out.print("请输入你发送文件的用户(在线)：");
                                    String getter = Utility.readString(50);
                                    System.out.print("请输入发送文件的路径(形式 d:\\xx.jpg)：");
                                    String src = Utility.readString(100);
                                    System.out.print("请输入把文件发送到对方的路径(形式 d:\\yy.jpg)：");
                                    String dest = Utility.readString(100);
                                    fileClientService.sendFileToOne(src, dest, userId, getter);
                                    break;
                                case "9":
                                    userClientService.logout();
                                    loop = false;
                                    break;
                                default:
                                    System.out.println("输入有误");
                            }
                        }

                    } else {
                        System.out.println("登录失败");
                        break;
                    }
                    break;
                case "9":
                    loop = false;
                    break;
                default:
                    System.out.println("输入有误");
            }
        }
    }

    public static void main(String[] args) {
        QQView qqView = new QQView();
        qqView.mainMenu();
    }
}
